<?php
/**
  * Mar 4, 2008
  *
  * Coded by: Ropu
  *
  */

require_once 'classes/dao/hackerDAO.php';
class Hacker {
  protected $id=-1;
  protected $nickname;
  protected $hackathon=null;
  protected $extra_info;
  protected $openSocial=array();
  protected $cv=null;
  protected $name;
  protected $email;
  protected $picture;
  protected $work;
  
  protected $apps = null;
  protected $favoriteApps = null;
  
  public function __construct($id) {
    $this->id = $id;
    HackerDAO::getById($this);
  }
  
/*
 * Getters
 */
  public function getId() {
    return $this->id;
  }
  
  public function getApps() {
    if(is_null($this->apps)) {
      $this->apps = AppDAO::getByHacker($this->id);
    }
    return $this->apps;
  }
  
  public function getFavoriteApps() {
    if(is_null($this->favoriteApps)) {
      $this->favoriteApps = AppDAO::getFavoriteByHacker($this->id);
    }
    return $this->favoriteApps;
  }
  
  public function getNickname() {
    return $this->nickname;
  }
  
  public function getHackathon() {
    return $this->hackathon;
  }
  
  public function getHackathonId() {
    if(!($this->hackathon instanceof Hackathon)) {
      return null;
    }
    return $this->hackathon->getId();
  }
  
  public function getExtraInfo() {
    return $this->extra_info;
  }
  
  public function getCV() {
    return $this->cv;
  }
  
  public function getName() {
    return $this->name;
  }
  
  public function getEmail() {
    return $this->email;
  }
  
  public function getPicture() {
    return $this->picture;
  }
  
  public function getWork() {
    return $this->work;
  }
  
  
/*
 * Setters
 */  
  public function setNickname($nickname) {
    $this->nickname = $nickname;
  }
  
  public function setHackathon($id) {
    $this->hackathon = new Hackathon($id);
  }
  
  public function setExtraInfo($extra_info) {
    $this->extra_info = $extra_info;
  }
  
  public function setOpenSocial(Array $openSocial) {
    $this->openSocial = $openSocial;
  }
  
  public function setCV($cv) {
    $this->cv = $cv;
  }
  
  public function setName($name) {
    $this->name =$name;
  }
  
  public function setEmail($email) {
    $this->email = $email;
  }
  
  public function setPicutre($picture) {
    $this->picture = $picture;
  }
  
  public function setWork($work) {
    $this->work = $work;
  }
  
  
  public function addApp(App &$app) {
    $app->setHackerId($this->id);
    return $app->save();
  }
  
  public function addFavoriteApp(App $app) {
    return AppDAO::addFavorite($app->getId(), $this->id);
  }
  
  public function removeFavoriteApp(App $app) {
    return AppDAO::removeFavorite($app->getId(), $this->id);
  }
  
  public function rateApp(App $app, $rate) {
    return AppDAO::rate($app->getId(), $rate, $this->id);
  }
  
  public function save() {
    return HackerDAO::save($this);
  }
}
